#include <vcl.h>
#pragma hdrstop




#include <System.hpp>


Comp a1 = 0.0, b1 = 0.0, q1 = 0.0, a2 = 0.0, b2 = 0.0, q2 = 0.0, c = 0.0, i = 0.0, t1 = 0.0, t2 = 0.0, t3 = 0.0, l = 0.0, d = 0.0;


Comp __fastcall cdiv( Comp m, Comp n )
{
  Comp result = 0.0;
  result = Trunc( double( m ) / n );
  return result;
}


Comp __fastcall cmod( Comp m, Comp n )
{
  Comp result = 0.0;
  result = m - cdiv( m, n ) * n;
  return result;
}


Comp __fastcall gcd( Comp m, Comp n )
{
  Comp result = 0.0;
  if ( n == 0 )
    result = m;
  else
    result = gcd( n, cmod( m, n ) );
  return result;
}


Comp __fastcall lcm( Comp m, Comp n )
{
  Comp result = 0.0;
  result = cdiv( m * n, gcd( m, n ) );
  return result;
}
  //try

int main(int argc, char* argv[])
{
  Read( a1 ); Read( b1 ); Read( q1 ); Read( a2 ); Read( b2 ); ReadLn( q2 );
  if ( ( a2 > b1 ) || ( a1 > b2 ) )
  {
    WriteLn( 0 );
      //readln;
    return;
  }
  if ( ( a2 == b1 ) || ( a1 == b2 ) )
  {
    WriteLn( 1 );
      //readln;
    return;
  }
  if ( a1 > a2 )
  {
    t1 = a1;
    t2 = b1;
    t3 = q1;
    a1 = a2;
    b1 = b2;
    q1 = q2;
    a2 = t1;
    b2 = t2;
    q2 = t3;
  }
  l = lcm( q1, q2 );
  d = b1 - a2;
  if ( cmod( d, l ) > 0 )
    WriteLn( cdiv( d, l ) + 1, 0, 0 );
  else
    WriteLn( cdiv( d, l ) + 1, 0, 0 );

    //max
    //for I := 0 to List.Count - 1 do

    //writeln(lcm(q1, q2));
    //readln;
    /* TODO -oUser -cConsole Main : Insert code here */
  /*except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;  */
  return 0;
}
